﻿<UserControl x:Class="Scrabble.Views.GameView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="180" d:DesignWidth="800">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="ShowIfTrue" />

        <Style x:Key="RightAlignCellStyle" TargetType="DataGridCell">
            <Setter Property="TextBlock.TextAlignment" Value="Right"/>
        </Style>

        <Style x:Key="HeaderStyle" TargetType="TextBlock">
            <Setter Property="Foreground" Value="Whitesmoke" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="Padding" Value="2" />
        </Style>

        <DataTemplate x:Key="PlayerName">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="20" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Image Source="/Assets/tick.png" Height="16" Visibility="{Binding Path=Player.IsActive, Converter={StaticResource ShowIfTrue}}" />
                <TextBlock Grid.Column="1" Text="{Binding DisplayName}" VerticalAlignment="Center" Padding="2" />
            </Grid>
        </DataTemplate>

    </UserControl.Resources>
    <DockPanel Margin="4">

        <!-- Left Panel -->
        <DockPanel DockPanel.Dock="Left" Margin="0,0,4,0">
            <DockPanel Width="300">
                <StackPanel DockPanel.Dock="Top" >
                    <StackPanel.Resources>
                        <ResourceDictionary Source="/Themes/DataGridStyles.xaml" />
                    </StackPanel.Resources>
                    
                    <!-- Player List -->
                    
                    <TextBlock Style="{StaticResource HeaderStyle}">Players</TextBlock>
                    <DataGrid DockPanel.Dock="Top" x:Name="PlayerList" ItemsSource="{Binding Items}" SelectedItem="{Binding ActiveItem}" 
                            FrozenColumnCount="1" IsReadOnly="true" Style="{StaticResource DataGridStyle}" CanUserReorderColumns="false" CanUserSortColumns="false">

                        <DataGrid.Columns>
                            <DataGridTemplateColumn Header="Name" CellTemplate="{StaticResource PlayerName}" MinWidth="160" />
                            <DataGridTextColumn Header="Score" MinWidth="60" Binding="{Binding Path=Player.CurrentScore, Mode=OneWay}" HeaderStyle="{StaticResource CenterAlignHeaderStyle}" CellStyle="{StaticResource RightAlignCellStyle}" />
                            <DataGridTextColumn Header="Time" MinWidth="65" Binding="{Binding Path=Player.TimeInGame, StringFormat=h\\:mm\\:ss, Mode=OneWay}" HeaderStyle="{StaticResource CenterAlignHeaderStyle}" CellStyle="{StaticResource RightAlignCellStyle}" />
                        </DataGrid.Columns>
                    </DataGrid>
                    <TextBlock DockPanel.Dock="Top" Style="{StaticResource HeaderStyle}">Plays by <Run Text="{Binding Path=ActiveItem.DisplayName, Mode=OneWay}"/></TextBlock>
                </StackPanel>

                <!-- Event Log -->
                <ContentControl x:Name="ActiveItem" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />
            </DockPanel>
        </DockPanel>

        <!-- Right Panel -->
        <DockPanel DockPanel.Dock="Right" Margin="4,0,0,0">
            <TextBlock DockPanel.Dock="Top" Style="{StaticResource HeaderStyle}">Legal Words</TextBlock>
            <ContentControl x:Name="TileUsageSummary" DockPanel.Dock="Bottom" />
            <TextBlock DockPanel.Dock="Bottom" Style="{StaticResource HeaderStyle}">Tile Usage</TextBlock>
            <ContentControl x:Name="WordSearch" Margin="0,0,0,4" MaxWidth="{Binding ElementName=TileUsageSummary, Path=ActualWidth}"  />
        </DockPanel>

        <Viewbox Stretch="Uniform" MaxWidth="680">
            <ContentControl x:Name="Board" />
        </Viewbox>
    </DockPanel>
</UserControl>
